#Boa:Frame:Frame_Clientes

import wx
from ControleCliente import *
from MainFrame import *
from editarCli_Frame import *
from CadastroCli_Frame import *

def create(parent):
    return Frame_Clientes(parent)

[wxID_FRAME_CLIENTES, wxID_FRAME_CLIENTESBACKTOMENU, 
 wxID_FRAME_CLIENTESCADASTRARC, wxID_FRAME_CLIENTESEXCLUIRC, 
 wxID_FRAME_CLIENTESLISTCLIENTES, wxID_FRAME_CLIENTESPESQUISARC, 
 wxID_FRAME_CLIENTESSTATICBITMAP1, wxID_FRAME_CLIENTESSTATICBOX1, 
 wxID_FRAME_CLIENTESSTATICTEXT1, wxID_FRAME_CLIENTESSTATICTEXT3, 
 wxID_FRAME_CLIENTESTEXTCTRL1, 
] = [wx.NewId() for _init_ctrls in range(11)]

class Frame_Clientes(wx.Frame):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_FRAME_CLIENTES, name=u'Frame_Clientes',
              parent=prnt, pos=wx.Point(536, 81), size=wx.Size(665, 647),
              style=wx.DEFAULT_FRAME_STYLE, title=u'Frame_Clientes')
        self.SetClientSize(wx.Size(649, 609))
        self.SetBackgroundColour(wx.Colour(255, 255, 255))
        self.Center(wx.BOTH)

        self.staticBox1 = wx.StaticBox(id=wxID_FRAME_CLIENTESSTATICBOX1,
              label=u"Cristina's Hair - Cadastro de Clientes",
              name='staticBox1', parent=self, pos=wx.Point(16, 16),
              size=wx.Size(608, 371), style=0)
        self.staticBox1.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))

        self.cadastrarC = wx.Button(id=wxID_FRAME_CLIENTESCADASTRARC,
              label=u'Cadastrar Novo Cliente', name=u'cadastrarC', parent=self,
              pos=wx.Point(32, 56), size=wx.Size(128, 56), style=0)
        self.cadastrarC.Bind(wx.EVT_BUTTON, self.OnCadastrarCButton,
              id=wxID_FRAME_CLIENTESCADASTRARC)

        self.pesquisarC = wx.Button(id=wxID_FRAME_CLIENTESPESQUISARC,
              label=u'Pesquisar', name=u'pesquisarC', parent=self,
              pos=wx.Point(512, 72), size=wx.Size(80, 24), style=0)
        self.pesquisarC.Bind(wx.EVT_BUTTON, self.OnPesquisarCButton,
              id=wxID_FRAME_CLIENTESPESQUISARC)

        self.excluirC = wx.Button(id=wxID_FRAME_CLIENTESEXCLUIRC,
              label=u'Exlcuir Cliente', name=u'excluirC', parent=self,
              pos=wx.Point(32, 136), size=wx.Size(128, 56), style=0)
        self.excluirC.Bind(wx.EVT_BUTTON, self.OnExcluirCButton,
              id=wxID_FRAME_CLIENTESEXCLUIRC)

        self.listclientes = wx.ListBox(choices=[],
              id=wxID_FRAME_CLIENTESLISTCLIENTES, name=u'listclientes',
              parent=self, pos=wx.Point(184, 136), size=wx.Size(424, 208),
              style=0)
        self.listclientes.SetLabel(u'')
        self.listclientes.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))
        self.listclientes.Bind(wx.EVT_RIGHT_DCLICK,
              self.OnListclientesRightDclick)
        self.listclientes.Bind(wx.EVT_LISTBOX, self.OnListclientesListbox,
              id=wxID_FRAME_CLIENTESLISTCLIENTES)
        self.listclientes.Bind(wx.EVT_LEFT_DCLICK,
              self.OnListclientesLeftDclick)

        self.backtomenu = wx.Button(id=wxID_FRAME_CLIENTESBACKTOMENU,
              label=u'Voltar para o Menu', name=u'backtomenu', parent=self,
              pos=wx.Point(32, 288), size=wx.Size(128, 56), style=0)
        self.backtomenu.Bind(wx.EVT_BUTTON, self.OnBacktomenuButton,
              id=wxID_FRAME_CLIENTESBACKTOMENU)

        self.textCtrl1 = wx.TextCtrl(id=wxID_FRAME_CLIENTESTEXTCTRL1,
              name='textCtrl1', parent=self, pos=wx.Point(184, 72),
              size=wx.Size(312, 21), style=0, value=u'')

        self.staticText1 = wx.StaticText(id=wxID_FRAME_CLIENTESSTATICTEXT1,
              label=u'Pesquisar Clientes', name='staticText1', parent=self,
              pos=wx.Point(184, 48), size=wx.Size(124, 19), style=0)
        self.staticText1.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD,
              False, u'Times New Roman'))

        self.staticText3 = wx.StaticText(id=wxID_FRAME_CLIENTESSTATICTEXT3,
              label=u'Nome', name='staticText3', parent=self, pos=wx.Point(216,
              120), size=wx.Size(28, 13), style=0)

        self.staticBitmap1 = wx.StaticBitmap(bitmap=wx.Bitmap(u"logotipo300dpi-30%.jpg",
              wx.BITMAP_TYPE_JPEG), id=wxID_FRAME_CLIENTESSTATICBITMAP1,
              name='staticBitmap1', parent=self, pos=wx.Point(16, 408),
              size=wx.Size(608, 176), style=0)

    def __init__(self, parent):
        self._init_ctrls(parent)
        c = ControleCliente()
        c.verificarArquivo()
        for cliente in c.getListaDeClientes():
            self.listclientes.Append(cliente.GetNomeCompleto())

    def OnBacktomenuButton(self, event):
        import MainFrame
        tela = MainFrame.create(None)
        tela.Show()
        self.Close()

    def OnCadastrarCButton(self, event):
        tela = CadastroCli_Frame(None)
        tela.Show()
        self.Close()

    def OnPesquisarCButton(self, event):
        self.listclientes.Clear()
        nome = self.textCtrl1.GetValue()
        
        a = ControleCliente()
        
        x = a.procurarClienteNome(nome)
        for cliente in x:
            self.listclientes.Append(cliente.GetNomeCompleto())


    def OnExcluirCButton(self, event):
        pos = self.listclientes.GetSelection()
        nome = self.listclientes.GetString(pos)
        obj = ControleCliente()
        lista = obj.procurarClienteNome(nome)
        cliente = lista[0]
        
        a = ControleCliente()
        a.excluirCliente(cliente.GetClienteID())
        
        self.listclientes.Delete(pos)
        
        wx.MessageBox('Cliente Removido Com Sucesso', 'Clientes', wx.OK)
        

    def OnListclientesLeftDclick(self, event):
        pos = self.listclientes.GetSelection()
        nome = self.listclientes.GetString(pos)
        obj = ControleCliente()
        lista = obj.procurarClienteNome(nome)
        cliente = lista[0]
        
        tela = editarCli_Frame(None)
        tela.Show()    
        self.Close()   

        tela.textCtrl1.SetValue(cliente.GetClienteID())
        tela.textCtrl2.SetValue(cliente.GetNomeCompleto())
        tela.textCtrl3.SetValue(cliente.GetTelefone())
        tela.textCtrl4.SetValue(cliente.GetEmail())
        tela.textCtrl5.SetValue(str(cliente.GetDataNasc().day))
        tela.textCtrl6.SetValue(str(cliente.GetDataNasc().month))
        tela.textCtrl7.SetValue(str(cliente.GetDataNasc().year))
         
        

        
    def OnListclientesListbox(self, event):
        a = self.listclientes.GetSelections()
        event.Skip()    

    def OnListclientesRightDclick(self, event):
        event.Skip()
